<template>
  <div class="home">
    nihao
    <p @click="countjia">count:{{ this.$store.state.count }}</p>
  <div>
    <input  v-model="username" placeholder="用户姓名"><br>
    <input  v-model="age" placeholder="年龄"><br>
    <button @click="saveInfo" > 提交</button><br>
  </div>
  </div>
  <hr>
</template>

<script>
// @ is an alias to /src

export default {
  data() {
    return {
      id: 1,
      count: 0,
      username: "",
      age: '',
    };
  },
  methods: {
    countjia() {
      this.$store.dispatch("countjia", this.n);
      //console.log(this.$store.state.count);
    },
    saveInfo(){
      console.log(this.username);
      this.$store.dispatch('addUser',{id:this.id++,username:this.username,age:this.age});
      this.username='';
      this.age='';

    }
  },
};
</script>
